package cn.newtouch._04_sync;

import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;

public class Producer {
    public static void main(String[] args) throws Exception {
        //1.获取生产者对象
        DefaultMQProducer producer = new DefaultMQProducer("sync_producer_group");
        //2.设置nameservser地址
        producer.setNamesrvAddr("localhost:9876");
        //3.启动
        producer.start();
        //4.生产消息并发送
        Message message = new Message("sync", "hei", "书山有路勤为径！！".getBytes(StandardCharsets.UTF_8));
        SendResult send = producer.send(message);
        System.out.println(send);

        //5.关闭
        producer.shutdown();
    }
}
